package com.lai.hospital.controller;

import com.lai.hospital.annotation.OptLog;
import com.lai.hospital.constant.OptTypeConst;
import com.lai.hospital.dto.CaseDTO;
import com.lai.hospital.entity.Case;
import com.lai.hospital.service.CaseService;
import com.lai.hospital.vo.Result;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import java.util.List;

/**
 * @author : lai
 * @version V1.0
 * @Project: hospital-springboot
 * @Package com.lai.hospital.controller
 * @Description: 病例控制器
 * @date Date : 2022年12月07日 11:27
 */
@RestController
@Api(value = "病例模块")
public class CaseController {


    @Autowired
    private CaseService caseService;


    /**
     * 根据患者id获取病例列表
     * @param patientId 患者id
     * @return {@link Result<?>} 病例列表
     */
    @GetMapping("/admin/listCase/{patientId}")
    @ApiOperation(value = "根据患者id获取病例列表")
    public Result<List<Case>> listCase(@PathVariable("patientId")Integer patientId){
        return Result.ok(caseService.listCase(patientId));
    }

    /**
     * 根据患者id获取病例列表
     * @param patientId 患者id
     * @return {@link Result<?>} 病例列表
     */
    @GetMapping("/user/listCase/{patientId}")
    @ApiOperation(value = "根据患者id获取病例列表")
    public Result<List<CaseDTO>> listCaseByPatientId(@PathVariable("patientId")Integer patientId){
        return Result.ok(caseService.listCaseByPatientId(patientId));
    }

    /**
     * 根据病例id获取病例信息
     * @param caseId 病例id
     * @return {@link Result<?>} 病例信息
     */
    @GetMapping("/admin/user/case/{caseId}")
    @ApiOperation(value = "根据病例id获取病例信息")
    public Result<?> getCaseById(@PathVariable("caseId")Integer caseId){
        return Result.ok(caseService.getCaseById(caseId));
    }

    /**
     * 上传病例图片
     * @param file 文件
     * @return {@link Result<String>} 病例图片地址
     */
    @ApiOperation(value = "上传病例图片")
    @ApiImplicitParam(name = "file", value = "病例图片", required = true, dataType = "MultipartFile")
    @PostMapping("/doctor/user/case/upload")
    public Result<String> uploadCase(MultipartFile file) {
        return Result.ok(caseService.uploadCase(file));
    }

    /**
     * 新增或修改病例
     * @param cases 病例
     * @return
     */
    @ApiOperation(value = "新增或修改病例")
    @PostMapping("/user/saveOrUpdateCase")
    @OptLog(optType = OptTypeConst.SAVE_OR_UPDATE)
    public Result<?> saveOrUpdateCase(@RequestBody Case cases){
        caseService.saveOrUpdateCase(cases);
        return Result.ok();
    }



}
